from os import close
from toolSettingUi import Ui_ToolSetting
from PyQt5.QtWidgets import QWidget
from PyQt5 import QtGui,QtCore



class ToolSetting(QWidget, Ui_ToolSetting):

    def __init__(self,parent) -> None:
        super(ToolSetting,self).__init__()
        self.settingForm = Ui_ToolSetting()
        self.setupUi(self)
        self.parent = parent
        self.BitratelineEdit.setPlaceholderText('单位:bps')
        self.TxIdlineEdit.setPlaceholderText('PHY HEX')
        self.RxIdlineEdit.setPlaceholderText('HEX')
        self.FuncTxIdlineEdit.setPlaceholderText('PHY HEX')     
        self.StatuspushButton.clicked.connect(self.statuspushButtonclicked)
        self.BitratelineEdit.setValidator(QtGui.QIntValidator(0, 1000000))
        reg = QtCore.QRegExp('[A-Fa-f0-9]{3}')
        validator = QtGui.QRegExpValidator(self)
        validator.setRegExp(reg)
        self.TxIdlineEdit.setValidator(validator)
        self.RxIdlineEdit.setValidator(validator)
        self.FuncTxIdlineEdit.setValidator(validator)
        
    def closeEvent(self, a0: QtGui.QCloseEvent) -> None:
        return super().closeEvent(a0)

    def statuspushButtonclicked(self):
        self.parent.testerInitSetting()
        self.close()